from datetime import timedelta
from flask import Flask, current_app
import settings
from apps.goods.views import goods_bp
from apps.user.views import user_bp
from apps.user.models import User
from apps.goods.models import Goods
import os


def create_app():
    app = Flask(__name__, template_folder='../templates', static_folder='../static')
    app.register_blueprint(user_bp)
    app.register_blueprint(goods_bp)
    # 解决返回数据乱码问题
    app.config['JSON_AS_ASCII'] = False
    app.config['SECRET_KEY'] = os.urandom(30)
    # 文件上传大小限制
    # app.config['MAX_CONTENT_LENGTH'] = 1 * 1024 * 1024
    # 指定session过期时间
    app.config['PERMANENT_SESSION_LIFETIME'] = timedelta(hours=1)
    app.config.from_object(settings.DevelopmentConfig)
    return app
